﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Web.Script.Serialization;
using System.Windows.Forms;

namespace weather
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //获取天气和解析  
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://www.weather.com.cn/data/sk/101010200.html");
            request.Timeout = 5000;
            request.Method = "GET";
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            StreamReader sr = new StreamReader(response.GetResponseStream());
            string jsonstr = sr.ReadLine();
            textBox1.Text = jsonstr;
            JavaScriptSerializer j = new JavaScriptSerializer();
            Weather weathe = new Weather();
            weathe = j.Deserialize<Weather>(jsonstr);
            textBox2.Text= weathe.weatherinfo.city+"\t"+weathe.weatherinfo.temp+"\t"+weathe.weatherinfo.time;

        }
    }
}
